package net.nohaven.proj.javeau.fs.real;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.nohaven.proj.javeau.fs.exceptions.EntityNotFoundException;
import net.nohaven.proj.javeau.fs.model.FSItem;

public class RFSRoots extends RFSDirectory {
	private static final Date FAKE_DATE = new Date(0);

	public RFSRoots() throws EntityNotFoundException {
		super();
		setName("ROOTS");
	}

	public boolean canWrite() {
		return false;
	}

	public Date getModificationDate() {
		return FAKE_DATE;
	}

	public String getPath() {
		return "<roots>";
	}

	public RFSDirectory getParent() {
		return null;
	}

	public FSItem[] getContents() {
		File[] roots = File.listRoots();

		List<FSItem> retList = new ArrayList<FSItem>();

		for (File root : roots) {
			try {
				retList.add(new RFSDirectory(root));
			} catch (EntityNotFoundException e) {
				continue;
			}
		}

		FSItem[] ret = new FSItem[retList.size()];

		return retList.toArray(ret);
	}

}
